﻿using OestsServer.Net;
using System;
using Utils;

namespace OestsServer
{
    /// <summary>
    /// 调试信息记录类
    /// </summary>
    public static class MyDebug
    {
        public static string ServerInfo;
        public static string ConnectCountDes
        {
            get
            {
                string str = string.Format("平台服务连接数:({0})-仿真服务连接数:({1})", ServerController.Instance.OESPServerListener.ClientManager.ConnectCount,
                    ServerController.Instance.UnityServerListener.ClientManager.ConnectCount);
                return str;
            }
        }

        public static void WhileReadKey()
        {
            ConsoleKeyInfo cki = new ConsoleKeyInfo();
            string strInputTipe = "输入指令:[C:清屏] [E:查看异常信息] [L:查看当前连接数] [P:显示传输数据] [Q:退出程序]";
            LogNetDebug.LogInfo(strInputTipe);
            do
            {
                if (Console.KeyAvailable)
                {
                    cki = Console.ReadKey(false);
                    //	LogNetDebug.LogInfo("You pressed the '{0}' key.", cki.Key);
                    switch (cki.Key)
                    {
                        case ConsoleKey.C:
                            Console.Clear();
                            LogNetDebug.LogInfo(OestsDataBase.SqlHelper.ip);
                            LogNetDebug.LogInfo(ServerInfo);
                            //  Log(strInputTipe);
                            break;
                        case ConsoleKey.E:
                            Console.Clear();
                            LogNetDebug.LogInfo(ServerInfo);
                            for (int i = 0; i < LogNetDebug.ErrorInfoList.Count; i++)
                            {
                                LogNetDebug.LogErrorUnSave(LogNetDebug.ErrorInfoList[i]);
                            }
                            break;
                        case ConsoleKey.L:
                            LogNetDebug.LogInfo(ConnectCountDes);
                            break;
                        case ConsoleKey.P:
                            ClientChannel.IsPrint = !ClientChannel.IsPrint;

                            string str;
                            if (!ClientChannel.IsPrint)
                            {
                                str = "显示传输数据";
                                Console.Clear();
                                LogNetDebug.LogInfo(OestsDataBase.SqlHelper.ip);
                                LogNetDebug.LogInfo(ServerInfo);
                            }
                            else
                                str = "隐藏传输数据";
                            strInputTipe = string.Format($"输入指令:[C:清屏] [E:查看异常信息] [L:查看当前连接数] [P:{str}] [Q:退出程序]");
                            break;
                        case ConsoleKey.Q:
                            break;
                        default:
                            LogNetDebug.LogInfo(strInputTipe);
                            break;
                    }
                }
            }
            while (cki.Key != ConsoleKey.Q);
        }

    }
}
